In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
import plotly.express as px
In [2]:
size=10000
#facebook
facebook_budget=15*4
conversion=[21,57]
reach=[554,1600]

#ecommerce
ali_price=12.35
shipping=0
selling_price=(ali_price+shipping)+(ali_price+shipping)*1.4

#payment_gate
two_checkout=(selling_price+shipping)*0.035+0.35
stripe=(selling_price+shipping)*0.029+0.3

#arrays
prior_arr=np.empty(size)
posterior_arr=np.empty(size)
ecom_revenu_arr=np.empty(size)
ali_cost_arr=np.empty(size)
two_checkout_cost_arr=np.empty(size)
stripe_cost_arr=np.empty(size)
profit_two_arr=np.empty(size)
profit_stripe_arr=np.empty(size)
    
for i in range(size):
    
    prior=np.random.beta(np.mean(conversion),(np.mean(reach)-np.mean(conversion)))
    posterior=np.random.binomial(np.mean(reach),prior)
        
    ecom_revenu=selling_price*posterior*4
    ali_cost=(ali_price+shipping)*posterior*4
    two_checkout_cost=two_checkout*posterior*4
    stripe_cost=stripe*posterior*4
    
    profit_two=ecom_revenu-ali_cost-two_checkout_cost-facebook_budget
    profit_stripe=ecom_revenu-ali_cost-stripe_cost-facebook_budget
    
    prior_arr[i]=prior
    posterior_arr[i]=posterior
    ecom_revenu_arr[i]=ecom_revenu
    ali_cost_arr[i]=ali_cost
    two_checkout_cost_arr[i]=two_checkout_cost
    stripe_cost_arr[i]=stripe_cost
    profit_two_arr[i]=profit_two
    profit_stripe_arr[i]=profit_stripe
df=pd.DataFrame(data={"prior_arr":prior_arr,"posterior_arr":posterior_arr,"ecom_revenu_arr":ecom_revenu_arr,
                   "ali_cost_arr":ali_cost_arr,"two_checkout_cost_arr":two_checkout_cost_arr,"stripe_cost_arr":stripe_cost_arr,
                   "profit_two_arr":profit_two_arr,"profit_stripe_arr":profit_stripe_arr})
print("Selling price is:",selling_price)
px.histogram(df,x="profit_two_arr",marginal='box').show()
px.histogram(df,x="prior_arr",marginal='box').show()
px.histogram(df,x="posterior_arr",marginal='box').show()
px.histogram(df,x="ali_cost_arr",marginal='box').show()
Selling price is: 29.64
In [49]:
round(df,3)
Out[49]:
prior_arr posterior_arr ecom_revenu_arr ali_cost_arr two_checkout_cost_arr stripe_cost_arr profit_two_arr profit_stripe_arr
0 0.036 44.0 5216.64 2173.6 244.182 204.083 2738.858 2778.957
1 0.036 41.0 4860.96 2025.4 227.534 190.168 2548.026 2585.392
2 0.035 39.0 4623.84 1926.6 216.434 180.891 2420.806 2456.349
3 0.048 51.0 6046.56 2519.4 283.030 236.550 3184.130 3230.610
4 0.036 42.0 4979.52 2074.8 233.083 194.806 2611.637 2649.914
... ... ... ... ... ... ... ... ...
9995 0.026 29.0 3438.24 1432.6 160.938 134.509 1784.702 1811.131
9996 0.041 55.0 6520.80 2717.0 305.228 255.103 3438.572 3488.697
9997 0.040 38.0 4505.28 1877.2 210.885 176.253 2357.195 2391.827
9998 0.038 49.0 5809.44 2420.6 271.930 227.274 3056.910 3101.566
9999 0.052 58.0 6876.48 2865.2 321.877 269.018 3629.403 3682.262

10000 rows × 8 columns

In [26]:
np.mean(conversion)/np.mean(reach)
Out[26]:
0.03574744661095636
In [33]:
beta=np.random.beta(np.mean(conversion),(np.mean(reach)-np.mean(conversion)),size=200)
binom=np.random.binomial(np.mean(reach),beta,size=200)
px.histogram(x=binom,marginal='box').show()
In [ ]: